package ru.jexp.mvc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ASubscriber implements ISubscriber {

	private List<IListener> listeners = new ArrayList<IListener>();

	public final void addListener(IListener listener) {
		listeners.add(listener);
	}

	public final void notifyAll(Event e) {
		List<IListener> copyListener = new ArrayList<IListener>(listeners);
		for (Iterator<IListener> iterator = copyListener.iterator(); iterator
				.hasNext();) {
			IListener listener = (IListener) iterator.next();
			if (!listener.equals(e.sender))
				listener.handle(e);
		}
	}

	public final void removeListener(IListener listener) {
		listeners.remove(listener);
	}

	public final void clearAll()
	{
		listeners.clear();
	}
}
